import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

const DataSource = () => import('@/views/admin/dataSource/DataSource.vue');

/* Layout */
import Layout from '@/layout';
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/operationReport',
    children: [{
      path: 'operationReport',
      name: '运行报表',
      component: () => import('@/views/operationReport/index'),
      meta: { title: '运行报表', icon: 'dashboard', affix: true }
    }]
  },
  {
    path: '/projectManagement',
    component: Layout,
    redirect: '/projectManagement',
    children: [{
      path: 'projectManagement',
      name: '项目管理',
      component: () => import('@/views/projectManagement/index'),
      meta: { title: '项目管理', icon: 'dashboard' }
    }
    ]
  },
  {
    path: '/projectManagement3',
    component: Layout,
    redirect: '/projectManagement3',
    children: [{
      path: 'projectManagement',
      name: '执行器管理',
      component: () => import('@/views/actuatorManagement/ActuatorManagement'),
      meta: { title: '执行器管理', icon: 'dashboard' }
    }
    ]
  },
  {
    path: '/dataSource',
    component: Layout,
    redirect: '/dataSource',
    children: [{
      path: 'dataSource',
      name: '数据源管理',
      component: DataSource,
      meta: {
        title: '数据源管理',
        icon: 'dashboard'
      }
    }]
  },
  // 404 page must be placed at the end !!!

  // 404 page 必须放在最后面
  { path: '*', redirect: '/404', hidden: true }
];

const createRouter = () => new Router({
  // mode: 'history', // 加上histrory ,链接没有#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
});

const router = createRouter();
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
